﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CollectionSorting : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var comments = new List<Comment>();

        Random r = new Random();
        for (int i = 0; i < 20; i++)
        {
            var wds = new Ipsum().GetWords(5);

            var c = new Comment();
            c.CommentData = wds;
            c.DateEntered = DateTime.Now.AddDays(r.Next(24));
            c.Id = r.Next(300).ToString();

            comments.Add(c);
        }
        SortByCommentData eCommentsort = new SortByCommentData();
        SortByCommentDataRev eCommentsortRev = new SortByCommentDataRev();
        SortByDate eDate = new SortByDate();

        comments.Sort(eCommentsortRev);
        lblOriginal.Text = CreateOut(comments);




        comments.Sort(eCommentsort);
        lblSorted.Text = CreateOut(comments);

    }

    private static string CreateOut(List<Comment> comments)
    {
        var sb = new System.Text.StringBuilder();
        foreach (Comment c in comments)
        {
            sb.AppendFormat("{0} {1} {2}<br>", c.CommentData.PadRight(60, '_'), c.DateEntered.ToString("MM.dd.yyyy").PadLeft(15, '_'), c.Id.PadLeft(10, '_'));
        }
        return sb.ToString();
    }
}
